Setting up the Module System

Are you finished with the theory? I want to start modding now.

Yes, I am. So, now let's start the modding. You want to setup a Module System, don't you? Well then, just go to the thread where we summarise downloads, the Warband Modder's Download Repository, and get yourself a fresh ModSys for your particular game of choice. (You're looking for the "Download Module System" section, can't miss it!)

Now. In order to be able to compile the files into game-readable text files, full of numbers and numbers and numbers, and to make your awesome mod come true, you need Python (the language). Having a real pet python might help, but don't count on it. Now, don't go rushing into downloading the latest Python. Here's something really important that you should know: The ModSys does NOT work with any Python newer than 2.x.[1] Fortunately, the same thread you've already got open also features a link to the Python website, so you've been saved a Googling; grab the latest 2.x.x version from there.

Now all you have to do is to install Python. Using Admin rights, please. Oh, it's a good idea to install it in its preferred C:\Python27 directory (if you're still using Python 2.7 in your day and age, oh reader from the future!).
Next up. Go to your Environment Variables to see if everything is OK. For those that don't know what Environment Variables are - well, these are OS things, which your Windows uses. You will only have interest in the "PATH" variable. Now open that window and get to business.

							
								Windows XP -> My Computer (right-click) -> Properties -> Advanced -> Environment Variables
Windows 7,8 -> My Computer (right-click) -> Properties -> Advanced system settings -> Environment Variables
Scroll that list until you find the "'Path"', then click it and hit the "Edit" button down there. This Path variable is basically just a string of paths to certain things which are important for your OS. It's different on every computer.
In order for your compiler to work without any hacks or fixes, you must have your Python folder in your Path variable. For an example, if you did install your Python in C:\Python27, then you should add
							
								;C:\Python27
							
						

at the end of the Path. Do NOT alter the Path in any other way! As it contains important system stuff, it's definitely NOT recommended. Just add that ;C:\Python27 if it's not there. I think it won't be there, since I had to enter it manually. I think.

Anyways, notice the semicolon (;) that is before the C:\Python27? Entries for different applications are separated with semicolons in the Path variable string, so you should add that semicolon so your OS knows what you're talking about. For Windows 10, be sure not to include the semicolon because it will cause an error during the module setup. And that's about it for setting up Python.

And where is the modding?

Modding comes next. Are you OK? Still alive, computer not exploded? Very well, keep reading! You've set your Pythonic compiler up, now it's time to compile the basis for your new mod.

Now, make sure you have permissions to read and write in your ModSys folder and in your Mount\&Blade folder (best is if you can freely change the whole folder). Now, open up your Mount&Blade\Modules, copy Native and paste it in the same place. Change the folder name to your new mod's name.

Now that you have your new mod folder, you have to make your ModSys use it. Open up your ModuleSystem folder, locate
module_info.py
and open it. Important! Do NOT double-click the file. If you do it, Python will think that you're trying to compile a Python program, and will basically do nothing. In order for you to edit ModSys files, you need to use a text editor. You can use Notepad, although I'd strongly recommend using Notepad++, a very powerful and free text editor. Python ships with IDLE, a text editor, but it's old and bad, don't use it. Anyways, open up your module_info.py with your favourite text editor, and you will see this:

							
								# Point export_dir to the folder you will be keeping your module
# Make sure you use forward slashes (/) and NOT backward slashes (\)

export_dir = "../WOTS/Modules/Native/"
#export_dir = "C:/Program Files/Mount&Blade/Modules/Native/"

Now this right here, "WOTS", is a remnant from pre-2005 (or so), when the game was (temporarily) called "Way of the Sword". If you've played the very first versions of M&B, you can see old stuff still hanging around.

Right. So, you see what you have to do. Now, let's give you some overhead. The # mark you see right there means that this line is a comment. If you're a programmer, you know what a comment is, if you're not - a comment is something that stands there for the programmer, not for the computer. Comments are used to take notes, make documentation and whatnot. Damned useful, comments are. Everything followed by a comment is invisible to the compiler, so if someone tells you you have to change both lines, tell them to **** off.
Change your export_dir (the non-commented one) so that it points to your new mod folder, and follow the lead for the slashes.

As you can see, the second (commented) line is not changed, and it works OK. Now, you've set your mod up. And here comes the first challenge.

Challenge? What challenge?

Don't worry, it's nothing. You have to double-click the build_module.bat file in your ModSys folder - this is the compiler. Now a console window will pop up and you will see some output.
If you've done everything correctly, you'll see a good output without any errors and you can be happy.

But if you've failed to do something from the above, you can get errors. The highest chance of an error you'll get is to see
							
								'python' is not recognized as internal or external command, operable program or batch file.
							
						

about twenty times in a row. What this means is that you haven't set up your "'Path"' variable properly. Feel free to consult the stickied How to fix "Python not recognised..." thread in the forum. If/When everything works OK, keep reading.

Uh... I'm getting a "'can't open file"' or something"' error! What do I do?

You must be sure to have Read/Write permissions to your ModSys folder, and to your new mod's folder, of course. You can try running the build_module.bat as an admin, it may work - I haven't tried it, I don't know. However, putting the ModSys folder on the Desktop or in My Documents is bound to fix the problem.

I'm getting another error!

Use the forum's search function (it's in the top-right corner) or ask a question in the Modding Q&A board. Do not make a new thread specifically for your question.

All right, my mod compiles properly. What now?

Well, my friend, this means you're done. You have the basis for your mod completed, and all that's left is the real modding itself.
One more thing you should know, though. As you probably noticed, there are four types of .py files in the ModSys folder. Read on below to understand their purposes.

  • header_*files - Header files contain constants for the game. You can change them, but it's generally not recommended or needed. If you want to define yourself a new constant, you can do it in the appropriate module_* file. All available operations are documented in header_operations.py.
  • ID_*files - ID files contain the numerical indexes for everything in your mod. In MABL/MBScript/whatever, everything can be looked at as a list of stuff represented by an index, and ID files contain these indexes. ID files get re-created with every compile you do, you don't need to change them yourself. You can use ID files to check what indexes your stuff has - if you get game errors that report an index but not a name, for an example.
  • module_*files - As you already saw, we edited module_info.py. Module files contain all the game stuff, and they are the ones that you will edit. They contain nearly everything - troops, items, scene props, scenes, etc. You are allowed to edit them. Backing up your ModSys folder from time to time is recommended.
  • process_*files - The process files are responsible for compiling your mod into the game's beloved numbers. Modification to these files seldom happens, and before you do anything, you have to be absolutely sure that you know what you're doing - but for a start, just don't touch them. The process files, unlike the other parts of the ModSys, are written in real Python.

But wait, aren't you going to tell me how to mod?!

This is a path that everyone must walk on their own. In other words, no, I'm not going to tell you how to mod. I will, however, give you some tips and links that will be useful for you.

Fine. What are they?

Here we go...

  • Firstly, grammar and attitude. Remember these two words, for they are very important. Write properly, be polite to others, and your chances of getting help will increase exponentially. Put spaces after punctuation marks, remember that "u" and "y" and other crap are not words but letters, and no "halp plox". Treat others as your equals, in the way that you want to be treated. Members with experience (that even spare time to answer your questions) should be treated with all the respect you (should) treat your mentors with. Don't be afraid to ask your questions and to use the word "please".
  • Stickied topics are your friend. Stickied topics are threads on the forum which always stay on the top, and do that because they are important. Reading them is always a good idea.
  • Read the forum rules. They aren't a lot, and are put quite shortly and understandably. Also remember to read the box that appears when you make a new topic. Read it at least once, it won't hurt you.
  • If you have a small question, do not make a topic about it. Post your question in the Modding Q&A board instead.
  • Use the forum search and/or Google search on the forum to find things you need.
  • The best way to learn modding is to try. Start off small, although that may seem boring as an advice. But trust me, I know it from experience. Starting off small is the good way to start; trying to make a gigantic project from the beginning is a very, very bad idea. Trust me.
  • You can read what each "operation" (i.e. ModSys function) does in header_operations.py.

Wait, how can I edit the World map?

Since you asked, here's something important. In modding, the term map refers only to the World Map, the one where you move around towns with your little guy. Multiplayer maps, called like that similarly to other MP games, are called scenes in the modding section. Know that, because it's highly annoying to come across a person who asks how to edit a map, while he's actually referring to a scene.

But let's get back on the question. To edit the World Map, you need a Map Editor application. There are a few in existence, but the most well-known of them all is Thorgrim's MapEditor. It was made for the old M&B, but it can work with Warband, no matter what people may be telling you. An alternative is Bloodpass' Warband Map Editor.

Demonwolf's tutorial How to make Campaign Maps is very good (I've followed it myself) and will get you started on the actual map editing.

Also, please note that the larger the map, the more cumbersome it is. Maps with loads of vertices (yes, the map is actually a 3D mesh), like more than 80000, will put a lot of pressure onto people's computers and should generally be avoided.

Is that it?

That's about it. Now it's time for you to venture into the big wide world of modding.

- Lumos

>> Continue to Module Syntax and Usage

    [1] That's actually a lie. If you're familiar with Python, you're free to re-write the Python "compiler" that the ModSys uses, and thus convert it to Python 3.